package dnavsim.variant;

import java.util.Enumeration;
import java.util.Vector;

public class VariantHandler {

	private static Vector<Variant> variantsOrdered = new Vector<Variant>();

	public static void addVariant(Variant v) {		
		int i = 0;
		for (Enumeration<Variant> enume = variantsOrdered.elements(); enume.hasMoreElements(); ) {
			if (enume.nextElement().getFrequency() > v.getFrequency())
				break;
			i++;
		}
		variantsOrdered.add(i, v);
	}
	
	public static Variant.TYPE chooseRandomVariant() {
		Math.random();
		double r = Math.random();
		Variant.TYPE result = Variant.TYPE.NONE;
		double freqSum = 0;
		for (int i=0; i<variantsOrdered.size(); i++) {
			Variant v = variantsOrdered.get(i);
			freqSum += v.getFrequency();
			if (r < freqSum) {
				result = v.getType();
				break;
			}
		}
		return result;
	}
	
}
